package tests;

import gameComponents.Board;
import gameComponents.Player;
import gamePieces.Queen;
import gameComponents.QueenGame;
import junit.framework.TestCase;

public class QueenGameTest extends TestCase {

	public QueenGameTest(String name) {
		super(name);
	}

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}
	
	/**
	 * Test QueenGame by adding queens (up to 8) to see if the game follows the rules
	 * Also tests PieceQueen and Board to make sure it works as the game is being played
	 * @author - Sabrina Gaudreau
	 */
	public final void testQueenGame() throws Exception {
		QueenGame gameWin = new QueenGame(); //test to see if possible to win
		QueenGame gameLose = new QueenGame(); //test to see if possible to lose
		Board board = new Board();
		Player p1 = new Player(1);
		Queen q1 = new Queen(0,6,p1);
				
		//Test to see if it is possible to add queen1 off the board
		assertFalse(q1.checkIfLegal(-1,-1));
		
		//Test to see if it is possible to add queen1 to the board
		//by checking in class Queen and in the Game class
		assertTrue(q1.checkIfLegal(0, 6));
		assertTrue(gameWin.legalMove(0,6));
		
		//Test to make sure the queen shows up on the board when added
		gameWin.placeQueen(0, 6);
		board.placePiece(0, 6, "Q", p1);
		assertEquals(board.getBoard()[0][6].toString(), "Q");
		assertEquals(board.getBoard()[0][0], null);	//this space should be empty
		assertFalse(gameWin.noWin()); //game has not been won yet
		
		//Test to see if we can add a second queen2 in a position
		//where it could be eaten by queen1
		assertFalse(gameWin.legalMove(2,4));
		
		//Test to see if it is possible to add queen2 to the game
		//and if it shows up on the board
		gameWin.placeQueen(1, 4);
		board.placePiece(1, 4, "Q", p1);
		assertEquals(board.getBoard()[1][4].toString(), "Q");
		assertFalse(gameWin.noWin()); //game has not been won yet
		
		//Testing to see if it is possible to win the game
		assertTrue(gameWin.legalMove(2,2));
		gameWin.placeQueen(2, 2);
		assertFalse(gameWin.noWin());
		assertFalse(gameWin.hasWon());

		
		assertTrue(gameWin.legalMove(3,0));
		gameWin.placeQueen(3, 0);
		assertFalse(gameWin.noWin());
		assertFalse(gameWin.hasWon());
		
		assertTrue(gameWin.legalMove(4,5));
		gameWin.placeQueen(4, 5);
		assertFalse(gameWin.noWin());
		assertFalse(gameWin.hasWon());
		
		assertTrue(gameWin.legalMove(5,7));
		gameWin.placeQueen(5, 7);
		assertFalse(gameWin.noWin());
		assertFalse(gameWin.hasWon());
		
		assertTrue(gameWin.legalMove(6,1));
		gameWin.placeQueen(6, 1);
		assertFalse(gameWin.noWin());
		assertFalse(gameWin.hasWon());
		
		assertTrue(gameWin.legalMove(7,3));
		gameWin.placeQueen(7, 3);
		assertTrue(gameWin.noWin());	//game has been won!!!
		assertTrue(gameWin.hasWon());	//game has been won :)
		
		//Test to see if it is possible to lose the game (when no
		//more possible moves are available.
		assertTrue(gameLose.legalMove(0,0));
		gameLose.placeQueen(0, 0);
		assertFalse(gameLose.noWin());
		assertFalse(gameLose.hasWon());

		assertTrue(gameLose.legalMove(2,1));
		gameLose.placeQueen(2, 1);
		assertFalse(gameLose.noWin());
		assertFalse(gameLose.hasWon());
		
		assertTrue(gameLose.legalMove(4,2));
		gameLose.placeQueen(4, 2);
		assertFalse(gameLose.noWin());
		assertFalse(gameLose.hasWon());
		
		assertTrue(gameLose.legalMove(1,3));
		gameLose.placeQueen(1, 3);
		assertFalse(gameLose.noWin());
		assertFalse(gameLose.hasWon());
		
		assertTrue(gameLose.legalMove(6,7));
		gameLose.placeQueen(6, 7);
		assertFalse(gameLose.noWin());
		assertFalse(gameLose.hasWon());
		
		assertTrue(gameLose.legalMove(7,4));
		gameLose.placeQueen(7, 4);
		assertFalse(gameLose.noWin());
		assertFalse(gameLose.hasWon());
		
		assertTrue(gameLose.legalMove(3,6));
		gameLose.placeQueen(3, 6);
		assertTrue(gameLose.noWin());	//user has not won and game is lost :(
		assertFalse(gameLose.hasWon());
	}
}
